<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<form id="form-plan-upd" class="p-3">
  <div class="form-group">
    <label for="id-upd-plan_id">计划编号</label>
    <input type="text" value="${plan.plan_id }" name="plan_id" class="form-control" id="id-upd-plan_id" readonly="readonly">    
  </div>
  <div class="form-group">
    <label for="id-upd-standard_id">产品规格编号</label>
    <input type="text" value="${plan.standard_id }" name="standard_id" class="form-control" id="id-upd-standard_id">    
  </div>
  <div class="form-group">
    <label for="id-upd-cus_id">客户编号</label>
    <input type="text" value="${plan.cus_id }" name="cus_id" class="form-control" id="id-upd-cus_id">    
  </div>
  <div class="form-group">
    <label for="id-upd-co_id">花色号编号</label>
    <input type="text" value="${plan.co_id }" name="co_id" class="form-control" id="id-upd-co_id">    
  </div>
  <div class="form-group">
    <label for="id-upd-plan_xh">生产顺序号</label>
    <input type="text" value="${plan.plan_xh }" name="plan_xh" class="form-control" id="id-upd-plan_xh">    
  </div>
  <div class="form-group">
    <label for="id-upd-plan_month">生产计划月份</label>
    <select id="getYear" name="getYear">
    	<option>请选择年份</option>
    </select>
    <select id="getMonth" name="getMonth">
    	<option>请选择月份</option>
    </select><br>
    <input type="hidden" id="plan_month" name="plan_month" class="form-control" id="id-add-plan_month">  
  
  </div>
  <div class="form-group">
    <label for="id-upd-plan_num">计划产量</label>
    <input type="text" value="${plan.plan_num }" name="plan_num" class="form-control" id="id-upd-plan_num">    
  </div>
  <div class="form-group">
    <label for="id-upd-plan_type">产品类型</label>
    <select id="select-plan_type" class="plan-select" name="plan_type">
    			<option value=''>请选择产品类型</option>
    			<option value='1'>白布产品</option>
    			<option value="2">染色产品</option>
    			<option value="3">无底色印花产品</option>
    			<option value="4">有底色印花产品</option>
  	</select>
  </div>
  
  <button type="button" id="bn-plan-doupd" class="btn btn-primary">修改</button>
</form>

<script>
	//获取当前年月
	var date=new Date();
	var year=date.getFullYear();

	var month=date.getMonth();

	for(var i=0;i<3;i++){
		$('#getYear').append("<option value='"+(year+i)+"'>"+(year+i)+"</option>");
	}
	for(var j=0;j<(12-month);j++){
		$('#getMonth').append("<option value='"+(month+j+1)+"'>"+(month+j+1)+"</option>");
	}
	//提交表单数据
	$('#bn-plan-doupd').click(function(){
		//获得年和月的值
		var getYear=document.getElementById("getYear").value;
		var getMonth=document.getElementById("getMonth").value;
		
		layer.confirm('你确实要修改该计划信息吗？', {icon: 3, title:'警告'}, function(index){
			
			//为plan_month添加年和月的值
			document.getElementById("plan_month").value=(getYear+"-"+getMonth);
			
			let loadLayerIdx = layer.load();
			let arr=$('#form-plan-upd').serializeArray();
			let data={};
			for(let ele of arr){
				data[ele.name]=ele.value;
			}
			let jsonStr=JSON.stringify(data);
			
			$.ajax({
				url:'manager',
				data:jsonStr,
				method:'put',
				contentType:'application/json',
				dataType:'json'
			})
			.done(function(result){
				layer.close(loadLayerIdx);
				if(result.success){
					reloadData();
					
					layer.msg(result.message, {
							  icon: 1,
							  time: 1000 //1秒关闭（如果不配置，默认是3秒）
							}
					);
					layer.close(layerIdx);
					
				}else{
					layer.msg(result.message, {icon: 6});
				}
			})
			.fail(function(xhr){
				layer.close(loadLayerIdx);
				layer.msg('服务器错误！', {icon: 6});
			});
			layer.close(index);
				
			});
		
	})
	
</script>
